package org.ngbx.demo.flink.clickevent.statistics.event;

import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserClickStatisticsPeriodicallyCompletedEvent {

    private Long statisticsStartTime;

    private Long statisticsEndTime;

    private Long userId;

    private Long totalClicks = 0L;

    @Override
    public boolean equals(final Object o) {
        if (this == o) {
            return true;
        }

        if (o == null || getClass() != o.getClass()) {
            return false;
        }

        final UserClickStatisticsPeriodicallyCompletedEvent that = (UserClickStatisticsPeriodicallyCompletedEvent) o;
        return totalClicks.equals(that.totalClicks) &&
                Objects.equals(statisticsStartTime, that.statisticsStartTime) &&
                Objects.equals(statisticsEndTime, that.statisticsEndTime) &&
                Objects.equals(userId, that.userId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(statisticsStartTime, statisticsEndTime, userId, totalClicks);
    }

    @Override
    public String toString() {
        return "ClickEventStatistics{" + "statisticsStartTime=" + LocalDateTime.ofInstant(Instant.ofEpochMilli(this.statisticsStartTime), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) +
                ", statisticsEndTime=" + LocalDateTime.ofInstant(Instant.ofEpochMilli(this.statisticsEndTime), ZoneId.systemDefault()).format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.SSS")) +
                ", userId='" + this.userId + '\'' +
                ", totalClicks=" + this.totalClicks +
                '}';
    }
}
